package StudyCode.summary.mycollection;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class NullSafeMergeOfTwoMaps {
	public static Map<Object, Object> mergeMaps(
			Map<Object, Object> overridingMap, Map<Object, Object> baseMap) {
		Map<Object, Object> mergedMap = new LinkedHashMap<>();

		if (baseMap == null && overridingMap != null) {
			mergedMap.putAll(overridingMap);
		} else if (overridingMap == null && baseMap != null) {
			mergedMap.putAll(baseMap);
		} else if (overridingMap != null) {
			mergedMap.putAll(baseMap);
			mergedMap.putAll(overridingMap);
		}
		return mergedMap;
	}
}
